package com.huiyan.hysys.controller;

import com.huiyan.hysys.bo.UserBo;
import com.huiyan.hysys.config.SystemConfig;
import com.huiyan.hysys.service.intf.UserService;
import com.huiyan.hysys.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@RestController
@CrossOrigin
@RequestMapping("/api/user/")
public class UserController {
    @Autowired
    private UserService service;

    //校验
    @GetMapping("/checkphone.do")
    public R check(String phone){
        return service.checkPhone(phone);
    }
    //校验
    @GetMapping("/checktoken.do")
    public R check(HttpServletRequest request){
        return service.checkToken(request.getHeader(SystemConfig.USER_TOKEN));
    }
    @PostMapping("/save.do")
    public R save(@RequestBody UserBo bo, HttpServletRequest request){
        return service.register(bo,request.getRemoteAddr());
    }
    @PostMapping("/login.do")
    public R login(@RequestBody UserBo bo, HttpServletRequest request){
       return service.login(bo,request.getRemoteAddr());
    }
    @PostMapping("/logincode.do")
    public R loginCode(@RequestBody UserBo bo, HttpServletRequest request){
        return service.loginCode(bo,request.getRemoteAddr());
    }
    @GetMapping("/loginout.do")
    public R loginOut(HttpServletRequest request){
        return service.loginOut(request.getHeader(SystemConfig.USER_TOKEN),request.getRemoteAddr());
    }
    @PostMapping("/getuser.do")
    public R get(HttpServletRequest request){
        return service.getToken(request.getHeader(SystemConfig.USER_TOKEN));
    }
}
